package cn.deschen.search.index.adUnit;

import cn.deschen.common.config.cache.Cache;
import cn.deschen.search.index.IndexAware;
import cn.deschen.search.index.adTag.AdTagObject;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @Author hanbin_chen
 * @Description 推广单元索引，三级索引
 * @DateTime 2021/6/6
 * @Version V1.0.0
 */
@Component
@EqualsAndHashCode
public class AdUnitIndex extends IndexAware<Long, AdUnitObject> {

    public static final String INDEX_TYPE = "UNIT";

    @Autowired
    public AdUnitIndex(Cache<String, AdUnitObject> cache) {
        super(cache, INDEX_TYPE);
    }

    /**
     * 匹配广告位类型
     *
     * @param positionType
     * @return
     */
    public Set<AdUnitObject> match(String positionType) {

        return storageMap.values().stream().filter(unit -> positionType.contains(unit.getPositionType()))
                .collect(Collectors.toSet());
    }
}
